// pages/login/login.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var token = options.token || '-1';
    this.setData({
      token: token
    })
  },

  /**
   * 登录成功
   */
  loginSuccess: function() {
    if (this.data.token != '-1') {
      var skipPage;
      app.Ajax({
        url: '/api/index.php?app=home&act=token',
        data: {
          token: this.data.token
        },
        success: (res) => {
          skipPage = res.page;
          if (skipPage == 'pages/homepage/homepage') {
            wx.switchTab({
              url: '../../' + skipPage,
            })
          } else {
            wx.redirectTo({
              url: '../../' + skipPage,
            })
          }
        },
        fail: (err) => {
          wx.switchTab({
            url: '../homepage/homepage',
          })
        }
      })
      return;
    }
    wx.switchTab({
      url: '../homepage/homepage',
    })
  }
})